﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

public partial class ShopBegin : ExtBaseRpt
{
    string mid;
    protected void Page_Load(object sender, EventArgs e)
    {
        mid = Request.Params["mid"];
        if (!X.IsAjaxRequest)
        {
            //BuildGridPanel(this.GridPanel1, mid, Session["UserID"].ToString());
            //this.comShop.GetStore().DataSource = QueryShop("");
            InsActLog(mid, "浏览");
        }
    }
    protected void BtnQureyUser(object sender, DirectEventArgs e)
    {
        string sql = @"select a.*,b.infoname from Bas_ShopBegin a inner join V_ShopList b on b.shopcode = a.shopcode " 
            + ((txtshop.Text == "") ? "" : "where a.shopcode like '%" + txtshop.Text + "%' or a.shopname like '%" + txtshop.Text + "%' order by a.shopcode");
        //QueryData(this.Store1, mid, sql);
        this.Store1.DataSource = mydb.DM_GetDateSet(sql);
        this.Store1.DataBind();
    }

    protected void BtnGetUser(object sender, DirectEventArgs e)
    {
        string sql = @"insert into Bas_ShopBegin
                        select a.ShopCode,a.ShopName,'','','','','',0,0.4,0.4,0.35,0.35,0.10,getdate(),'"+Session["UserCode"]+@"'  from V_Shop a 
                        left join Bas_ShopBegin b on b.ShopCode = a.ShopCode
                        where isnull(b.ShopCode,'') = ''";
        if(mydb.DM_ExecuteNonQuery(sql)!=-1){
            ShowBox("加载成功！");
        }else{
            ShowBox("加载失败！");
        }
        BtnQureyUser(null, null);
    }

    protected void RefreshDataSet(object sender, StoreReadDataEventArgs e)
    {
        BtnQureyUser(null,null);
    }
    protected void Store1_Submit(object sender, StoreSubmitDataEventArgs e)
    {
        //导出EXCEL
        ExtGridToExcel(mid,"xls",e.Xml,this.Response,this.Title);
    }
    [DirectMethod(Namespace = "CompanyX")]
    public void Edit2(string shopcode, string field, string oldValue, string newValue, object customer)
    {
        if (mydb.DM_ExecuteNonQuery("update Bas_ShopBegin set " + field + "='" + newValue + "',ModifyDate=getdate(),Modifer='"+Session["UserCode"]+"' where shopcode='" + shopcode + "'") != -1)
        {
            this.GridPanel1.GetStore().CommitChanges();
        }
        else
        {
            X.Msg.Notify(new NotificationConfig()
            {
                Title = "消息提示",
                Html = "修改失败！",
                Width = 250
            }).Show();
        }
    }
}